fix(install): place_config_template backup 变量 bash 3.2 安全 - #451
Merged
bigbrother666sh merged 1 commit intoJul 21, 2026
Merged
Conversation
macOS 自带 bash 3.2 在 set -eu 下对 `local var=$(cmd)` 有已知坑,
升级模式跑到 'Checking config health' 时报 `backup?: unbound variable`
(line 1169 cp $backup).
修法:
- backup 在函数顶部预绑定为空串 (local need_place=0 reason="" backup=""),
永不 unbound
- 后缀改用 $$.${RANDOM:-0} (始终有值、无命令替换), 弃用 $(date +%s ...)
- 消除 local-带-命令替换 模式, bash 3.2/5 通用
|
codes-factory-of-bg seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
bigbrother666sh
added a commit
that referenced
this pull request
Jul 21, 2026
…被误判 unbound (#453) macOS 用户 v5.6.0 升级模式跑到 [9/11] Placing config template 报 `reason?: unbound variable`(line 1174)。本地 Linux bash 5 同代码正常, 差异在 macOS 自带 /bin/bash 3.2。 根因(真因,非 PR #451 误判的绑定坑):bash 3.2 在 C locale 下把 未加花括号的 `$var` 后接多字节字符(全角()/→)的字节也算进变量名查找, `$reason)` 被查成 `reason)` → unbound,报错里 `?` 是全角 )的 C locale 渲染。 PR #451 的预绑定是对错因下药(绑定从来没问题),花括号才是真修。 修法: - place_config_template 内所有 $var 引用一律 ${var} 加花括号 - 多字节标点改 ASCII:→ 改 ->,()改 () - 每个变量单独 local 声明再纯赋值预绑(belt-and-suspenders,规避多变量一行 local 坑) - 顺手 brace 另 4 处同类风险引用(camoufox/weixin/awada warn、bind_weixin warn) install.ps1 有 8 处类似但 PowerShell 原生 UTF-8 解析无此坑,不动。 Co-authored-by: codes-factory-of-bg <bigbrother666@wiseflow.tech>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
macOS 自带 bash 3.2 在
set -eu下对local var=$(cmd)有已知坑,升级模式跑到[9/10] Checking config health时报backup?: unbound variable(line 1169cp "$config_path" "$backup").修法
backup在函数顶部预绑定为空串 (local need_place=0 reason="" backup=""),永不 unbound$$.\${RANDOM:-0}(始终有值、无命令替换),弃用$(date +%s 2>/dev/null || echo 0)local-带-命令替换 模式,bash 3.2/5 通用验证
本地 repro(真实 install.sh + set -euo pipefail + 极简 config):检测不健康 → 备份到
.bak.<pid>.<random>→ 放 template → exit 0,无 unbound。